﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vigenère
{
    /// <summary>
    /// 用类来实现加密
    /// </summary>
    public class Code
    {
        private string plaintext;
        private string key;
        public Code(string plaintext1, string key1)
        {
            plaintext = plaintext1;
            key = key1;
        }
        //加密函数
        public string encrypt()
        {
            //用来存储密钥要加的值
            int[] ints = new int[32];
            int i = 0;
            foreach (char c in key)
            {
                ints[i] = c - 'a';
                i++;
            }
            //把明文字符串转成字符型数组
            char[] plaintextOfChar = plaintext.ToCharArray();
            //把密文先用字符串数组存储
            char[] cypherOfChar = new char[32];
            for (i = 0; i < plaintextOfChar.Length; i++)
            {
                cypherOfChar[i] = Convert.ToChar(plaintextOfChar[i] + ints[i]);

            }
            //把字符串数组转为字符串
            //失败了
            //返回结果
           string str=new string(cypherOfChar);
            return str;
            //本身都有些问题，好像原本和密文的数太大，会跳出字母表
            //要保证明文和密钥数目一致

        }
    }
}
